package com.idealighter.game.games.errenniuniu.struct;

import com.idealighter.game.games.common.AbstractSeat;
import com.idealighter.game.games.common.SeatState;
import com.idealighter.game.games.common.niuniu.NiuNiuCard;
import com.idealighter.game.games.common.niuniu.NiuNiuCardsType;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledFuture;

/**
 * 二人牛牛座位.
 *
 */
public class ErRenNiuNiuSeat extends AbstractSeat {

  // 桌子所属牌桌
  public final ErRenNiuNiuTable table;
  // 是否叫过庄
  public boolean called = false;
  // 是否是庄家
  public boolean dealer = false;
  // 当前下注的筹码
  public long betedchips = 0;
  // 当前结算筹码
  public long billChips = 0;
  // 玩家的牌数据
  public final List<NiuNiuCard> cards = new ArrayList<>();
  // 玩家的牌最优牌(3+2)组合
  public final List<NiuNiuCard> bestCards = new ArrayList<>();
  // 当前牌型
  public NiuNiuCardsType cardsType = null;
  // 是否已经摊牌
  public boolean showdown = false;
  // 是否系统托管(已放弃)
  public boolean systemHosted = false;
  // 牛牛步骤(准备、叫庄、下注、摊牌)定时Future
  public ScheduledFuture<?> stepFuture = null;

  /**
   * 构造函数.
   * 
   * @param order .
   */
  public ErRenNiuNiuSeat(int order, ErRenNiuNiuTable table) {
    super(order);
    this.table = table;
  }

  /**
   * 另一个seat.
   * 
   * @return
   */
  public ErRenNiuNiuSeat otherSeat() {

    return table.seat1 == this ? table.seat2 : table.seat1;
  }

  /**
   * 重置座位数据 .
   */
  public void reset() {
    this.called = false;
    this.dealer = false;
    this.betedchips = 0;
    this.billChips = 0;
    this.totalChips = 0;
    this.cards.clear();
    this.bestCards.clear();
    this.cardsType = null;
    this.state = SeatState.SEATED;
    this.showdown = false;
    this.systemHosted = false;
    if (this.stepFuture != null) {
      this.stepFuture.cancel(false);
    }
  }

  /**
   * 重置座位数据除了totalChips .
   */
  public void resetButTotalChips() {
    long totalChips = this.totalChips;
    reset();
    this.totalChips = totalChips;
  }

  /**
   * 清空座位数据 .
   */
  public void clear() {
    this.playerId = 0;
    this.playerName = null;
    reset();
  }

  @SuppressWarnings("unchecked")
  @Override
  public ErRenNiuNiuTable table() {
    return table;
  }

}
